package com.tenement.controller;

import com.tenement.common.Axios;
import com.tenement.enums.RespBusiness;
import com.tenement.service.VoteService;
import com.tenement.vo.VoteVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 *  控制层。
 *
 * @author BertXie
 * @since 1.0.1
 */
@RestController
@RequestMapping("/vote")
@RequiredArgsConstructor
@Api(tags = "投票管理接口")
public class VoteController {


    private final VoteService voteService;

    @ApiOperation(value = "获取投票的详情")
    @GetMapping("infoCount/{resolutionId}")
    public Axios infoCount(@PathVariable Long resolutionId) {
        return Axios.success(voteService.infoCount(resolutionId));
    }

    @ApiOperation(value = "用户进行投票")
    @PostMapping
    public Axios vote(@RequestBody VoteVo voteVo) {
        return voteService.vote(voteVo) ? Axios.success(RespBusiness.SUCCESS) : Axios.error(RespBusiness.NO_VOTE);
    }

}
